package com.atguigu.spzx.manager.controller;

import com.atguigu.spzx.manager.service.SysUserService;
import com.atguigu.spzx.model.dto.system.SysUserDto;
import com.atguigu.spzx.model.entity.system.SysUser;
import com.atguigu.spzx.model.vo.common.Result;
import com.github.pagehelper.PageInfo;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/admin/system/sysUser/")
@CrossOrigin(allowCredentials = "true" , originPatterns = "*" , allowedHeaders = "*")
public class SysUserController {

    @Autowired
    private SysUserService sysUserService;

    @GetMapping("/getSysUserListByPage/{page}/{limit}")
    public Result<PageInfo<SysUser>> getSysUserListByPage(@PathVariable Integer page, @PathVariable Integer limit, SysUserDto sysUserDto){
        PageInfo<SysUser> pageInfo= sysUserService.getSysUserListByPage(page,limit,sysUserDto);
        return Result.ok(pageInfo);
    }


    @PutMapping("/updateSysUser")
    public Result updateSysUser(@RequestBody SysUser sysUser){
        sysUserService.updateSysUser(sysUser);
        return Result.ok(null);
    }

    @PostMapping("/saveSysUser")
    public Result saveSysUser(@RequestBody SysUser sysUser){
        sysUserService.saveSysUser(sysUser);
        return Result.ok(null);
    }


    @DeleteMapping("/deleteById/{userId}")
    public Result deleteById(@PathVariable Long userId){
        sysUserService.deleteById(userId);
        return Result.ok(null);
    }

}
